/*
 * address page
**/
<template>
<div class="mod-items">
	<div class="weui-panel">
        <a class="weui-cell">
            <div class="weui-cell__hd"><i class="i-adr"></i></div>
            <div class="weui-cell__bd p-desc">
				<p>{{addinfo.consignee}} {{addinfo.mobile}}</p>
				<p>{{addinfo.province_name}} {{addinfo.city_name}} {{addinfo.district_name}} {{addinfo.address}}</p>
			</div>
        </a>
    </div>
    <div class="weui-panel scroll">
        <div class="weui-media-box weui-media-box_small-appmsg" v-if="addList.length < 10">
            <a class="weui-cell" @click="add">
                <div class="weui-cell__hd"><i class="i-add"></i></div>
                <div class="weui-cell__bd p-title"><p>添加奖品地址</p></div>
            </a>
        </div>
        <div class="weui-cell" v-for="(el, index) in addList" @click="selectIt(index)">
        	<div class="weui-cell__hd p-desc">
        		<p>{{el.consignee}} {{el.mobile}}</p>
				<p>{{el.province_name}} {{el.city_name}} {{el.district_name}} {{el.address}}</p>
        	</div>
            <div class="weui-cell__ft p-title"><i class="i-edit" @click.stop="update(index)"></i></div>
        </div>
    </div>
    <div class="quick-footernav"><span class="ui-btn" @click="back">&nbsp;&nbsp;返回&nbsp;&nbsp;</span></div>
    <adds v-show="addShow" @refreshAdd="addView" ref="adds"></adds>
</div>
</template>
<script>
import adds from 'src/page/pay/add'
export default {
  data () {
    return {
      addShow: false,
      addList: [], // 地址列表
      addinfo: {}, // 默认
      updateId: ''
    }
  },
  components: {
    adds
  },
  mounted () {
  },
  methods: {
    initData (addList) {
      this.addList = addList
      this.addinfo = addList[localStorage.addId]
    },
    selectIt (index) {
      localStorage.addId = index
      this.addinfo = this.addList[index]
    },
    add () {
      this.addShow = true
    },
    update (index) {
      this.updateId = index
      this.$refs.adds.initData(this.addList[index])
      this.addShow = true
    },
    addView (param) {
      this.addShow = false
      if (!param.mobile) return
      if (param.address_id) { // 修改
        this.addList[this.updateId] = param
      } else { // 添加
        localStorage.addId = this.addList.length
        this.addList.push(param)
        this.addinfo = param
      }
    },
    back () {
      this.$emit('refreshAdd')
    }
  }
}
</script>
<style scoped>
  .i-adr,.i-add,.i-edit{width: 0.14rem;height: 0.14rem;background: url(../../assets/imgs/pay/adr.png);background-size: 100%;display:block;}
  .i-adr{width:0.12rem;height:0.16rem;margin-right:0.02rem;}
  .i-add{background-image: url(../../assets/imgs/pay/add.png);}
  .i-edit{width:0.27rem;height:0.27rem;background-image: url(../../assets/imgs/pay/edit.png);}
  .p-title{color:#ffa200;font-size: 0.13rem;padding-left: 0.08rem;}
  .p-desc{color: #333; font-size: 0.13rem;padding-left: 0.1rem;flex: 1;}
  .quick-footernav{background: transparent;border: none;}
  .scroll{overflow-y: auto; height: 100%; padding-bottom: 1.5rem;-webkit-overflow-scrolling : touch}
  .mod-items{overflow: hidden;}
</style>
